function getBeijingTimeParts() {
  const now = new Date();
  const beijingTimestamp = now.getTime() + 8 * 60 * 60 * 1000; // 转换为北京时间的时间戳
  const beijingDate = new Date(beijingTimestamp);
  return {
    hours: beijingDate.getUTCHours(),
    minutes: beijingDate.getUTCMinutes(),
    seconds: beijingDate.getUTCSeconds(),
    milliseconds: beijingDate.getUTCMilliseconds(),
  };
}

function calculateSunPhase() {
  const parts = getBeijingTimeParts();
  // 计算总小时数（含小数部分）
  const totalHours =
    parts.hours +
    parts.minutes / 60 +
    parts.seconds / 3600 +
    parts.milliseconds / (3600 * 1000);

  // 计算相对于06:00的时间差
  const delta = (totalHours - 6 + 24) % 24;
  const sunPhase = delta / 24;

  return sunPhase >= 1 ? 0 : sunPhase; // 确保在06:00时返回0
}

// 每秒更新并输出sunPhase
setInterval(() => {
  const phase = calculateSunPhase();
  world.sunPhase = phase;
  // console.log(`SunPhase: ${phase.toFixed(8)}`); // 输出此时sunPhase的值并保留8位小数
}, 1000);
